<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style media="screen">
        body {
            background: #000;
        }
        #canvas {
            background: #fff;
            display: block;
            margin: 100px auto;
        }
    </style>
</head>
<body>
    <canvas id="canvas" width="600" height="400"></canvas>
    <script type="text/javascript">
        let canvas  = document.querySelector('#canvas');
        let ctx = canvas.getContext('2d');
        let r = 0;

        function next() {
            r++;
            ctx.beginPath();
            ctx.clearRect(0, 0, 300, 300);
            ctx.save();
            ctx.translate(150, 125);
            ctx.rotate(r * Math.PI / 180);
            ctx.strokeStyle = 'red';
            ctx.strokeRect(-100,-75,200,150);
            ctx.restore();
            window.requestAnimationFrame(next);
        }

        window.requestAnimationFrame(next);

    </script>
</body>
</html>
